package com.lw.smartdevice.controller.advice;

import com.lw.smartdevice.dto.R;
import com.lw.smartdevice.exceptions.MyBaseException;
import com.lw.smartdevice.exceptions.MyErrorCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Administrator
 * @version 1.0
 * @description:
 * @date 2022/3/17 14:18
 */
@ControllerAdvice
@ResponseBody
public class MyControllerAdvice {
    @ExceptionHandler(MyBaseException.class)
    public static R processException(MyBaseException e){
        return R.getR(e.getCode(),e.getMessage(),null);
    }

    @ExceptionHandler(Exception.class)
    public static R processException(Exception e){
        return R.getR(MyErrorCode.FAIL,"网络故障，请检查网络",null);
    }
}
